package com.tiantian.judge.dubbo;

import cn.hutool.core.bean.BeanUtil;
import com.tiantian.api.RemoteJudgeService;
import com.tiantian.api.domain.vo.RemoteJudgerVo;
import com.tiantian.judge.domain.entity.Judger;
import com.tiantian.judge.domain.vo.JudgeVo;
import com.tiantian.judge.mapper.JudgerMapper;
import com.tiantian.judge.service.JudgeService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author tiantian
 */
@Service
@DubboService
@RequiredArgsConstructor
public class RemoteJudgeServiceImpl implements RemoteJudgeService {

    private final JudgerMapper judgerMapper;
    private final JudgeService judgeService;

    @Override
    public List<RemoteJudgerVo> getJudgerList(RemoteJudgerVo remoteJudgerVo) {
        List<JudgeVo> judgeList = judgeService.getJudgeList(null);
        return BeanUtil.copyToList(judgeList, RemoteJudgerVo.class);
    }

    @Override
    public int allotAnswererForJudger(List<RemoteJudgerVo> remoteJudgerVoList) {
        List<Judger> judgerList = BeanUtil.copyToList(remoteJudgerVoList, Judger.class);
        for (Judger sysJudger : judgerList) {
            sysJudger.setUpdateTime(LocalDateTime.now());
            sysJudger.setUpdateBy("系统分配");
        }
        return judgerMapper.updateJudgerBatch(judgerList);
    }

}
